#ifndef TRAFFICVIEW_H
#define TRAFFICVIEW_H

#include <QGraphicsView>
#include "vehicle.h"
#include "point.h"
#include "streetmap.h"
#include "trafficcontrol.h"
#include "vehicleframe.h"
#include "vehicleitem.h"
#include "trafficcontrolitem.h"

class TrafficView : public QGraphicsView
{
  Q_OBJECT

public:
  TrafficView(QWidget* parent = 0);

  void refreshGraphics();
  void rebuildMapGraphics();
  void clearGraphics(const bool clearScene=false);
  void showVectors(bool show=true);
  void showForces(bool show=true);
  void zoom(bool zoomIn);
  void centerOnContent();
  void setSceneRectWithMargin(const float margin=200.0f);
  void setSelectedVehicle(Vehicle *vehicle);
  void setSelectionOnly(const bool value);

signals:
  void selectionChanged();

protected:

  virtual void wheelEvent(QWheelEvent *event);

  QGraphicsScene mScene;
  QMap<QString, VehicleItem*> mVehicleItems;
  QMap<QString, TrafficControlItem*> mTrafficControlItems;

private:
  QGraphicsPathItem* createRoad(StreetMap::Road* r);
  QGraphicsPathItem* createIntersection(StreetMap::Intersection* i,
                                        const StreetMap::RoadList& roads);


  bool mShowVectors;
  bool mShowForces;
  bool mShowLinesForSelectionOnly;
  Vehicle *mSelectedVehicle;
  float mZoomLevel;
};

#endif
